import axios from 'axios';
import router from '../router/index.js'
//axios.defaults.baseURL = "http://10.180.13.55:8080/";
//axios.defaults.baseURL = "http://10.180.13.55:8080/";
//环境切换
//const debug = process.env.NODE_ENV !== 'production'
// if (debug) { // 开发环境配置
//     axios.defaults.baseURL = "http://localhost:62600/";
// }

axios.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
axios.defaults.headers["X-Requested-With"] = "XMLHttpRequest";
axios.defaults.headers["Cache-Control"] = "no-cache";
axios.defaults.headers["pragma"] = "no-cache";
axios.defaults.withCredentials = true;

//添加http权限跳转
axios.interceptors.response.use(
	response=>{
		if(response.status===200){
			return Promise.resolve(response);
		}
		else{
			return Promise.reject(response);
		}
	},
	error=>{
		if(error.response.status){
			switch(error.response.status){
				case 401:
					//跳转到登陆界面
					router.replace('./login')
					break;
				default:
			}
		}
		return Promise.reject(error.response);
	}
);

export default axios;